PACK block

Short summary

Name

PACK

→POU type

→function

Category

Standard (non-safe), ConvertEnh

Conform to →IEC-standard

(plus) not defined in IEC-standard

Graphical interface

Available since

version 1.50.0 (for Neuron Power Engineer) – initial variant

version 3.2.5 (for library Standard) – corrected functionality for platforms created by a system integrator

version 3.8.0 (for library Standard) – changed behavior when the return value is connected to an input of a generic data type

version 3.8.0 (for library Standard (non-safe)): block moved in this library

Functionality

The block returns the transferred values of the bytes connected to the inputs IN0 – IN7. In case of target systems saving data in little →endian format, the byte of input IN0 is transferred to the lowest significant byte of the return value, the byte of input IN7 to the highest significant byte of the return value. A reversed behavior is true for target systems saving data in big endian format.

Special cases (see under "Example for usage within ST-editor"): 

  • If the size of the result data type (number of bytes representing the data type) is > than the number of the connected input bytes, the higher significant bytes of the return value remain not-initialized.
    In case of BOOL values for the return value, TRUE is returned for each value ≠ 0 at input IN0

  • If more input bytes are connected than the result data type can hold, only the lower significant input bytes are transferred to the return value. In case of target systems saving data in little endian format, these are the inputs positioned in the upper part of the block.

The block reports an error whenthe output is connected to a block input of a generic data type (e.g. the input of a TO_INT block). This behavior is caused due to the statement anyOutputMustBeConcreteResolved in the interface of the PACK block. See under "Properties for implementing vendor blocks" for details on this statement. To fix such an error, you might want to declare an auxiliary variable and assign the calls to this auxiliary variable (see under "Typing of expressions" for details on this workaround for a nested usage of PACK together with other blocks). 

Inputs, return value

 

Identifier

→Data type

Description

Inputs:

IN0

BYTE

1st value

IN1

BYTE

2nd value

... (extensible until)

IN7

BYTE

8th value

Return value:

REALLREALUSINTUINTUDINTULINTSINTINTDINTLINTTIMEBOOLBYTEWORDDWORDLWORDDATE_AND_TIMEDATE or TIME_OF_DAY

 

Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

See:

Example for usage within ST-editor

The following example is valid for target systems saving data in little endian format. The calculated values are evaluated by using the Assert block.

FUNCTION_BLOCK ExamplePack
  VAR
    result1, result2 : DWORD;
    result2a : WORD;
  END_VAR
  result1 := PACK(IN0 := 16#01, IN1 := 16#02);                                  (* DWORD = 4 bytes *)
  result2 := PACK(IN0 := 16#01, IN1 := 16#02, IN2 := 16#04, IN3 := 16#07);
  result2a := PACK(IN0 := 16#01, IN1 := 16#02, IN2 := 16#03, IN3 := 16#04);     (* WORD = 2 bytes *)
 
  Assert(result1 = 16#0201);       (* '16#0201' equals to '513' (decimal). *)
  Assert(result2 = 16#07040201);   (* '16#07040201' equals '117_703_169' (decimal). *)
  Assert(result2a = 16#0201);      (* '16#0201' equals '513' (decimal). *)
END_FUNCTION_BLOCK  

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.